package com.uptown.nio;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author: Lixiaofei
 * @date: 2020/5/8 18:26
 */
public class NioFileChannel02 {
    public static void main(String[] args) throws IOException {
        File file = new File("e:\\file01.txt");
        FileInputStream fileInputStream = new FileInputStream(file);
        FileChannel fileChanne = fileInputStream.getChannel();

        ByteBuffer bytebuffer = ByteBuffer.allocate((int) file.length());
        fileChanne.read(bytebuffer);
        //将bytebuffer中字节数据转成字符
        System.out.println(new String(bytebuffer.array()));
        fileInputStream.close();
    }
}
